Then I remembered that in my final project I need to "detect plugins that are inserted". What I thought was to ask my instructor what would be the bigger choice, photoresistors, pogopines or Hall effect sensors. In the end I chose the Hall effect sensor (with the help of Abdon's super marmot) because I use the magnets and with that I solve the problem of fixing the chips to the device. I didn't decide in time and the eagle assembly of the plate was complicated. We decided to test all the sensors in one to take advantage of the time and test for my final project.
//Constants
const int buttonPin = 3;
const int PIN = 4;
//Variables
int buttonState = 0;
int flag=0;
void setup() {
//Input or output?
pinMode(PIN, OUTPUT);
pinMode(buttonPin, INPUT_PULLUP);
digitalWrite(PIN, LOW);
}
void loop(){
//Read button state
buttonState = digitalRead(buttonPin);
//If button pressed...
if (buttonState == HIGH) { //SI SE PRESIONA PASA VCC
//turn led on & an
if ( flag == 0){
digitalWrite(PIN, HIGH);
flag=1; //change flag variable
}
//button pressed again, turn led off
else if ( flag == 1){
digitalWrite(PIN, LOW);
flag=0; //change flag variable again
}
}
}